package de.fhd.pms.model;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * The java bean class for {@link Fahrt} objects It specifies:
 * <ul>
 * <li>DB-Table</li>
 * <li>get-/set-methods</li>
 * <li>constructors</li>
 * 
 * </ul>
 * 
 * @author Josef Fischer
 * @author Alexander Neetzel
 * @author Philipp Six
 */
@Entity
@Table(name = "tbl_fahrt")
public class Fahrt {
	@Id
	@GeneratedValue
	@Column(name = "pk_fahrt")
	private Integer id;
	private Date abfahrt;
	private Date ankunft;
	private long dauer;
	private float km;
	private float kosten;
	@ManyToOne
	@JoinColumn(name = "fk_kunde", nullable = false)
	private Kunde kunde;
	@ManyToOne
	@JoinColumn(name = "fk_auto", nullable = false)
	private Auto auto;

	public Fahrt() {
		abfahrt = new Date();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getAbfahrt() {
		return abfahrt;
	}

	public void setAbfahrt(Date abfahrt) {
		this.abfahrt = abfahrt;
	}

	public Date getAnkunft() {
		return ankunft;
	}

	public void setAnkunft(Date ankunft) {
		this.ankunft = ankunft;
	}

	public Kunde getKunde() {
		return kunde;
	}

	public void setKunde(Kunde kunde) {
		this.kunde = kunde;
	}

	public Auto getAuto() {
		return auto;
	}

	public void setAuto(Auto auto) {
		this.auto = auto;
	}

	public void setKm(float km) {
		this.km = km;
	}

	public float getKm() {
		return km;
	}

	public long getDauer() {

		return dauer;
	}

	public void setDauer(Date abfahrt, Date ankunft) {
		this.dauer = (ankunft.getTime() - abfahrt.getTime()) / 3600000 + 1;
	}

	public float getKosten() {
		return kosten;
	}

	public void setKosten(long dauer, float km) {

		if (this.getAuto().getTarif().equals("1")) {
			this.kosten = (float) (2.0 * dauer + km * 0.3);
		} else if (this.getAuto().getTarif().equals("2")) {
			this.kosten = (float) (2.5 * dauer + km * 0.4);
		} else {
			this.kosten = (float) (3.0 * dauer + km * 0.5);
		}

	}

}
